const filters = {
    // 渲染图片支持七牛以及学伴图库
    renderImg: function (value, width, height) {
        if (typeof value == 'undefined' || value == '') {
            return 'http://image.imoocs.org/image/upload_web/55974dfbb4b7067f746c5b26';
        }
        let fix_w_h = '';
        if (value.indexOf('http://') != -1 || value.indexOf('https://') != -1) {
            if (typeof width != 'undefined' && typeof width != 'undefined') {
                fix_w_h = '?imageView2/1/w/' + width + '/h/' + height;
            }
            return value + fix_w_h;
        }

        if (typeof width != 'undefined' && typeof width != 'undefined') {
            fix_w_h = '/' + width + '/' + height;
        }
        return 'http://image.imoocs.org/image/upload_web/' + value + fix_w_h;
    },
    //显示时间过滤器格式2017.9.10 17:00:00
    time: function (value) {
        var value = new Date(value);
        var year = value.getFullYear();
        var month = value.getMonth() + 1 > 9 ? value.getMonth() + 1 : "0" + (value.getMonth() + 1);
        var date = value.getDate() > 9 ? value.getDate() : "0" + value.getDate();
        var hour = value.getHours() > 9 ? value.getHours() : "0" + value.getHours();
        var minute = value.getMinutes() > 9 ? value.getMinutes() : "0" + value.getMinutes();
        var second = value.getSeconds() > 9 ? value.getSeconds() : "0" + value.getSeconds();
        return year + "." + month + "." + date + "    " + hour + ":" + minute + ":" + second;
    },
    time_line_to_point: function (value) {
        if (value) {
            return value.replace(/-/g, ".")
        }
    },
    //显示时间过滤器格式2017-9-10 17:00:00
    timeline: function (value) {
        var value = new Date(value);
        var year = value.getFullYear();
        var month = value.getMonth() + 1 > 9 ? value.getMonth() + 1 : "0" + (value.getMonth() + 1);
        var date = value.getDate() > 9 ? value.getDate() : "0" + value.getDate();
        var hour = value.getHours() > 9 ? value.getHours() : "0" + value.getHours();
        var minute = value.getMinutes() > 9 ? value.getMinutes() : "0" + value.getMinutes();
        var second = value.getSeconds() > 9 ? value.getSeconds() : "0" + value.getSeconds();
        return year + "-" + month + "-" + date + "    " + hour + ":" + minute + ":" + second;
    },
    money: function (value) {
        // if (value == 0) return '免费';

        value = parseFloat(value);
        return '￥' + (value / 100).toFixed(2);
    },
    dateFormat: function (value, format) {
        if (!Date.prototype.Format) {
            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "h+": this.getHours(), //小时
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt))
                    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt))
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            }
        }

        format = format || 'yyyy-MM-dd hh:mm:ss';

        return new Date(value).Format(format);
    },
}


export default filters